import Mock from 'mockjs';

const url = {
  tree: /\/mock\/tree/, // 获取图片
};

Mock.mock(url.tree, 'get', () => {
  function random(value: number) {
    return [...Array(Mock.mock(`@integer(1, ${value})`))].map(() => {
      const item = Mock.mock({
        id: '@guid',
        name: Mock.Random.cname(),
      });

      return item;
    });
  }

  return {
    code: 1,
    data: [
      {
        id: '01',
        name: '研发部',
        children: [
          ...random(2),
          ...Mock.Random.pick(
            [
              { id: '11', name: '研发一部', children: random(3) },
              { id: '12', name: '研发二部', children: random(5) },
              { id: '13', name: '研发三部', children: random(2) },
            ],
            1,
            3
          ),
        ],
      },
      { id: '02', name: '市场部', children: random(5) },
      { id: '03', name: '销售部', children: random(6) },
      { id: '04', name: '人力资源部', children: random(3) },
      { id: '05', name: '财务部', children: random(2) },
    ],
    msg: '成功',
  };
});
